home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
asm_msc1.arc
/
GETDIGIT.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-11-20
|
7KB
|
193 lines
page 64,132
title GETDIGIT-gets a digit for DOS batch file processing
subttl by Tony Alan Rhea 10/26/83
;
;
comment *
This program accepts a prompt from the command line and accepts
a one digit response to that prompt. On exit, the DOS ERRORLEVEL
is set to the digit. Non-numeric keys are ignored and <Ctrl><Break>
will not exit.
This program requires DOS 2.0.
Usage:
GETDIGIT prompt
where "prompt" is the message to displayed to the user.
Example batch file usage:
echo off
:menu
cls
echo ---IBM PC Menu--
echo 1 - Run Wordstar
echo 2 - Run Dbase II
echo 3 - Exit to DOS
GETDIGIT Please enter an option number:
if errorlevel 4 goto menu
if errorlevel 3 goto end
if errorlevel 2 goto dbase
if errorlevel 1 goto wordstar
:if we get here nothing matched -- try again
goto menu
:wordstar
cls
echo We would run WORDSTAR here.
pause
goto menu
:dbase
cls
echo We would run DBASE here.
pause
goto menu
:end
cls
echo on
Copyright (C) 1983 Tony Alan Rhea
This program may be copied and distributed for personal use
but not for profit provided this notice is included. Author makes
no warranty, expressed or implied, as to the correct nature and
operation of this software.
You may make and distribute as many copies of this program as you wish
for your PERSONAL use only ( NOT for business purposes, please! ).
Feel free to modify, mutilate, or adulterate this program. If you come
up with an bug or improvement, please let me know by writing me at this
address:
Tony A. Rhea
1030 Ivy Lane
Cary, NC 27511
If you do modify it, please give me credit in the program. This helps
to preserve my ego and increase my fame (but, unfortunately, NOT my
financial status). Also, I would appreciate a copy of the modified
version, preferably on disk (I'll be happy to return your diskette).
If you like this program ( or HATE it ), please let me know. Drop me
a line at the address given above.
This program has been submitted for publication in PC-WORLD magazine.
Revision history:
rev 1.0 10/26/83 { original release }
*
page
;
;
; Equates
;
;
zero equ '0'
nine equ '9'
cr equ 0dh
lf equ 0ah
dollar equ '$'
;
;
; Program entry point
;
;
cseg segment para 'code'
assume cs:cseg, ds:cseg, ss:nothing, es:cseg
org 100h ;for .COM file
entry proc near
mov ah,30h ;set function code -- get DOS version number
int 21h ;and request DOS service
cmp al,0 ;is it pre-DOS 2.0?
jne entry10 ;if not, continue
jmp dosexit ;else tell user & quit
;
;
; At this point we have DOS 2.0 or better. Get the prompt bytes from the
; command line paramter area and display them one at a time. Skip the first
; character which should be a blank and the last character which is a <CR>.
; The number of characters on the command line is at PSP+80h and the parms
; themselves start at PSP+81h, so we copy bytes starting at PSP+82h.
;
;
entry10 label near
push cs ;save CS and
pop ds ;point DS to CS -- establish addressability
xor cx,cx ;clear CX
mov si,80h ;set up address of parm length in PSP
mov cl,[si] ;and get parm length into CL
cmp cl,0 ;any prompt to display?
je entry30 ;if not, then just go read a key
dec cl ;else set CX one less cause we don't want the <CR>
mov si,82h ;point SI to command line parm (one space skipped)
entry20 label near
mov dl,[si] ;get a character into DL
mov ah,02 ;set function code -- display char in DL
int 21h ;and request DOS service
inc si ;point to next character and
loop entry20 ;loop until all characters have been displayed
page
;
;
; The prompt has been displayed. Get the user's response.
; Clear the keyboard buffer and wait for a key without echo.
; Keep monitoring the keyboard until we get a numeric entry.
; This input function DOES NOT check for control break!
; The cursor is at the end of the prompt.
;
;
entry30 label near
mov ax,0c07h ;set function code = read key clearing buffer
int 21h ;and request DOS service
cmp al,0 ;is it an extended code?
jne entry40 ;if not, skip over read of second char
mov ah,07 ;else set function code = read key from buffer
int 21h ;and request DOS to get it -- we throw it away
jmp entry30 ;and try again since we want a non-extended key
entry40 label near
cmp al,zero ;is the character < zero?
jb entry30 ;if so, then read another key
cmp al,nine ;is the character > nine?
ja entry30 ;if so, then read another key
;
;
; If we get here we have read a valid key into AL. Display the character
; and set the DOS errorlevel to that digit.
;
;
push ax ;save the character a moment
mov dl,al ;move the character into DL
mov ah,2 ;set function code -- display character in DL
int 21h ;and request DOS service
pop ax ;restore saved character into AX
sub al,zero ;convert '0' to 0, '1' to 1, etc...
mov ah,4ch ;set DOS function code -- terminate with errorlevel
int 21h ;and request DOS service (requested errorlevel returned)
page
;
;
; If we get here we don't have DOS 2.0. Tell user about it and terminate via
; function 0 (which works for all DOS versions).
;
;
dosexit label near
lea dx,errmsg1 ;point DX to DOS error msg
mov ah,9 ;set function code -- print string
int 21h ;and request DOS service
xor ax,ax ;set function code to zero -- program terminate
int 21h ;and request DOS service (no errorlevel returned)
entry endp
page
;
;
; Messages
;
;
errmsg1 db 'GETDIGIT requires DOS 2.0 or greater.', cr, lf, dollar
copyright db 'GETDIGIT -- Copyright (C) 1983 Tony Alan Rhea'
;
;
cseg ends
end entry